// 分类页逻辑
Page({
  data: {
    activeCategory: 1,
    categories: [],
    currentCategory: []
  },

  //获取产品分类下品牌列表数据
  loadProductcategorybrandlist(){
    wx.request({
      url: 'http://47.94.6.186:3001/api/pro/categorybrandlist',
      method:'GET',
      data:{category:''},
      success:res=>{
        this.setData({
          categories:res.data.data
        })
      }
    })
  },
  //获取产品分类列表数据
loadProdctCateList(){
wx.request({
  url: 'http://47.94.6.186:3001/api/pro/categorylist',
  method:'GET',
  success:res=>{
    this.setData({
      currentCategory:res.data.data
    })
  },
  fail:err=>{
    console.log(err);
    
  }
})
},
  onLoad() {
    this.setCurrentCategory();
    this.loadProductcategorybrandlist()
    this.loadProdctCateList()
  },

  switchCategory(e) {
    const categoryId = e.currentTarget.dataset.id;
    this.setData({
      activeCategory: categoryId
    });
    this.setCurrentCategory();
  },

  setCurrentCategory() {
    const currentCategory = this.data.categories.find(item => item.id === this.data.activeCategory);
    this.setData({
      currentCategory: currentCategory || this.data.categories[0]
    });
  },

  goToProductDetail(e) {
    const productId = e.currentTarget.dataset.id;
    wx.navigateTo({
      url: `/pages/product-detail/product-detail?id=${productId}`
    });
  }
});